home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / jwlthief.zip / JEWEL.CLS < prev    next >
Text File  |  1990-04-12  |  2KB  |  94 lines

  1. /* The jewel is a simple diamond polygon.    */
  2. /* It decays and erases itself when age <= 0 */
  3. /* It's offspring appears in a new location. */!!
  4.  
  5. inherit(Object, #Jewel, #(age      /* remaining lifetime */
  6. eraser   /* erasing device */
  7. pen      /* drawing device */
  8. rock     /* shape of jewel */
  9. rustRate /* jewel's death rate */
  10. x        /* xPos of jewel */
  11. y        /* xPos of jewel */), 2, nil)!!
  12.  
  13. now(JewelClass)!!
  14.  
  15. /* Create and initialize a new jewel. */
  16. Def  new(self | jewel, rockSize)
  17. { jewel := new(self:Behavior);
  18.   jewel.eraser := Call CreatePen(0, 1, 0xFFFFFF);  /* white */
  19.   ^jewel;
  20. }!!
  21.  
  22. now(Jewel)!!
  23.  
  24. /* Set up random age, rustRate */
  25. /* and random color to draw.   */
  26. /*******************************/
  27. Def  init(self)
  28. { age := random(150);
  29.   rustRate := random(4);
  30.   pen :=  Call CreatePen(0, 1, #(0x2000FF, /* red */
  31.                                  0x20FF00, /* green */
  32.                                  0xFF0000, /* blue */
  33.                                  0xFF009F  /* purple */
  34.           )[rustRate]);
  35.   rock := new(WinPolygon,            /* diamond */
  36.    tuple(point(x-3,y), point(x,y-3),
  37.          point(x+3,y), point(x,y+3),
  38.          point(x-3,y), point(x-2,y),
  39.          point(x,y+2), point(x+2,y),
  40.          point(x,y-2),  point(x-2,y)));
  41. }!!
  42.  
  43. /* Return the radius in pixels. */
  44. /********************************/
  45. Def  size(self)
  46. { ^3
  47. }!!
  48.  
  49. /* Return the remaining lifetime of the jewel */
  50. /**********************************************/
  51. Def  age(self)
  52. { ^age
  53. }!!
  54.  
  55. /* Decrement the jewel's lifetime. */
  56. /***********************************/
  57. Def  rust(self)
  58. { age := age - rustRate;
  59. }!!
  60.  
  61. /* Return the yPos of jewel. */
  62. /*****************************/
  63. Def  y(self)
  64. { ^y
  65. }!!
  66.  
  67. /* Return the xPos of jewel. */
  68. /*****************************/
  69. Def  x(self)
  70. { ^x
  71. }!!
  72.  
  73. /* Erase the jewel by drawing the bkgd color. */
  74. /**********************************************/
  75. Def  erase(self, hDC)
  76. { Call SelectObject(hDC, eraser);
  77.   draw(rock, hDC);
  78. }!!
  79.  
  80. /* Display the jewel with the selected color. */
  81. /* If this is the first draw, set a position  */
  82. /*   in the field rectangle.                  */
  83. /**********************************************/
  84. Def  draw(self, hDC, field)
  85. { if x = nil cor y = nil
  86.   then x := random(right(field)-size(self));
  87.        y := random(bottom(field)-size(self));
  88.        init(self);
  89.   endif;
  90.   Call SelectObject(hDC, pen);
  91.   draw(rock, hDC);
  92. }!!
  93.  
  94.